Kinetis SDK API Reference Manual  1.0.0-beta
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
SPI Slave Peripheral Driver

The section describes the programming interface of the SPI slave mode Peripheral driver. More...

Data Structures

struct  spi_slave_callbacks_t
 The set of callbacks used for SPI slave mode. More...
 
struct  spi_slave_user_config_t
 Definition of application implemented configuration and callback. More...
 

SPI Slave

void spi_slave_init (uint32_t instance, const spi_slave_user_config_t *config)
 Initializes the SPI module. More...
 
void spi_slave_shutdown (uint32_t instance)
 De-initializes the device. More...
 

SPI Slave Peripheral Driver

Overview

The SPI slave peripheral driver provides an easy way to use an SPI peripheral in slave mode.Data transfer is performed through callback functions.

Callbacks

To use this driver, first define several application callbacks. These are the callback functions that are set in the spi_slave_callbacks_t structure.The three callbacks are:

  • Data source
  • Data sink
  • Error notification
The first two callbacks are used to send and receive data. The third callback is invoked if an error occurs.The prototypes for the three callbacks are:

status_t dataSource(uint8_t * sourceByte, uint16_t instance);
status_t dataSink(uint8_t sinkByte, uint16_t instance);
void onError(status_t error);
All callbacks are invoked from IRQ state.

Setup

To initialize the SPI slave driver, first create and fill in the #spi_slave_config_t structure. This structure defines the callbacks and data format settings for the SPI peripheral. The structure is not required after the driver is initialized and can be allocated on the stack.This is an example of a config struct definition:

spi_slave_config_t config = {
{
appDataSource,
appDataSink,
appErrorHandler,
},
};

Data Structure Documentation

struct spi_slave_callbacks_t

Data Fields

spi_status_t(* dataSource )(uint8_t *sourceByte, uint16_t instance)
 Callback used to get byte to transmit. More...
 
spi_status_t(* dataSink )(uint8_t sinkByte, uint16_t instance)
 Callback used to put received byte. More...
 
void(* onError )(spi_status_t error)
 Callback used to report an SPI error. More...
 

Field Documentation

spi_status_t(* spi_slave_callbacks_t::dataSource)(uint8_t *sourceByte, uint16_t instance)
spi_status_t(* spi_slave_callbacks_t::dataSink)(uint8_t sinkByte, uint16_t instance)
void(* spi_slave_callbacks_t::onError)(spi_status_t error)
struct spi_slave_user_config_t

functions used by the SPI slave driver.

Data Fields

spi_slave_callbacks_t callbacks
 Application callbacks. More...
 
spi_clock_phase_t phase
 Clock phase setting. More...
 
spi_clock_polarity_t polarity
 Clock polarity setting. More...
 
spi_shift_direction_t direction
 Either LSB or MSB first. More...
 

Field Documentation

spi_slave_callbacks_t spi_slave_user_config_t::callbacks
spi_clock_phase_t spi_slave_user_config_t::phase
spi_clock_polarity_t spi_slave_user_config_t::polarity
spi_shift_direction_t spi_slave_user_config_t::direction

Function Documentation

void spi_slave_init ( uint32_t  instance,
const spi_slave_user_config_t config 
)

Saves the application callback info, turns on the clock to the module, enables the device, and enables interrupts. Sets the SPI to a slave mode.

Parameters
instanceInstance number of the SPI module.
configPointer to slave mode configuration.
void spi_slave_shutdown ( uint32_t  instance)

Clears the control register and turns off the clock to the module.

Parameters
instanceInstance number of the SPI module.